// This example shows how to unsubscribe from changes of all items. // // Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html . using System; using OpcLabs.EasyOpc.UA; using OpcLabs.EasyOpc.UA.OperationModel; namespace UADocExamples._EasyUAClient { class UnsubscribeAllMonitoredItems { public static void Main1() { UAEndpointDescriptor endpointDescriptor = "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"; // or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported) // or "https://opcua.demo-this.com:51212/UA/SampleServer/" // Instantiate the client object and hook events. var client = new EasyUAClient(); client.DataChangeNotification += client_DataChangeNotification; Console.WriteLine("Subscribing..."); client.SubscribeMultipleMonitoredItems(new[] { new EasyUAMonitoredItemArguments(null, endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10845", 1000), new EasyUAMonitoredItemArguments(null, endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10853", 1000), new EasyUAMonitoredItemArguments(null, endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10855", 1000) }); Console.WriteLine("Processing monitored item changed events for 10 seconds..."); System.Threading.Thread.Sleep(10 * 1000); Console.WriteLine("Unsubscribing..."); client.UnsubscribeAllMonitoredItems(); Console.WriteLine("Waiting for 5 seconds..."); System.Threading.Thread.Sleep(5 * 1000); Console.WriteLine("Finished."); } static void client_DataChangeNotification(object sender, EasyUADataChangeNotificationEventArgs e) { // Display value. if (e.Succeeded) Console.WriteLine($"{e.Arguments.NodeDescriptor}: {e.AttributeData.Value}"); else Console.WriteLine($"{e.Arguments.NodeDescriptor} *** Failure: {e.ErrorMessageBrief}"); } } }
# This example shows how to unsubscribe from changes of all items. # # Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html . #requires -Version 5.1 using namespace OpcLabs.EasyOpc.UA using namespace OpcLabs.EasyOpc.UA.OperationModel # The path below assumes that the current directory is [ProductDir]/Examples-NET/PowerShell/Windows . Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcUA.dll" Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcUAComponents.dll" [UAEndpointDescriptor]$endpointDescriptor = "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer" # or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported) # or "https://opcua.demo-this.com:51212/UA/SampleServer/" # Instantiate the client object. $client = New-Object EasyUAClient # Data change notification handler Register-ObjectEvent -InputObject $client -EventName DataChangeNotification -Action { # Display value. if ($EventArgs.Succeeded) { Write-Host "$($EventArgs.Arguments.NodeDescriptor): $($EventArgs.AttributeData.Value)" } else { Write-Host "$($EventArgs.Arguments.NodeDescriptor) *** Failure: $($EventArgs.ErrorMessageBrief)" } } Write-Host "Subscribing..." $handleArray = $client.SubscribeMultipleMonitoredItems(@( (New-Object UAMonitoredItemArguments( (New-Object UAAttributeArguments($endpointDescriptor, [UANodeDescriptor]"nsu=http://test.org/UA/Data/ ;i=10845")), 1000)), (New-Object UAMonitoredItemArguments( (New-Object UAAttributeArguments($endpointDescriptor, [UANodeDescriptor]"nsu=http://test.org/UA/Data/ ;i=10853")), 1000)), (New-Object UAMonitoredItemArguments( (New-Object UAAttributeArguments($endpointDescriptor, [UANodeDescriptor]"nsu=http://test.org/UA/Data/ ;i=10855")), 1000)) )) Write-Host Write-Host "Processing monitored item changed events for 10 seconds..." $stopwatch = [System.Diagnostics.Stopwatch]::StartNew() while ($stopwatch.Elapsed.TotalSeconds -lt 10) { Start-Sleep -Seconds 1 } Write-Host "Unsubscribing..." $client.UnsubscribeAllMonitoredItems() Write-Host "Waiting for 5 seconds..." Start-Sleep -Seconds 5 Write-Host "Finished."
# This example shows how to unsubscribe from changes of all items. # # Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html . # OPC client and subscriber examples in Python on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-Python . # The QuickOPC package is needed. Install it using "pip install opclabs_quickopc". import opclabs_quickopc import time # Import .NET namespaces. from OpcLabs.EasyOpc.UA import * from OpcLabs.EasyOpc.UA.OperationModel import * def dataChangeNotification(sender, e): # Display value. if e.Succeeded: print(e.Arguments.NodeDescriptor, ': ', e.AttributeData.Value, sep='') else: print(e.Arguments.NodeDescriptor, ' *** Failure: ', e.ErrorMessageBrief, sep='') endpointDescriptor = UAEndpointDescriptor('opc.tcp://opcua.demo-this.com:51210/UA/SampleServer') # or 'http://opcua.demo-this.com:51211/UA/SampleServer' (currently not supported) # or 'https://opcua.demo-this.com:51212/UA/SampleServer/' # Instantiate the client object and hook events. client = EasyUAClient() client.DataChangeNotification += dataChangeNotification print('Subscribing...') client.SubscribeMultipleMonitoredItems([ EasyUAMonitoredItemArguments( None, endpointDescriptor, UANodeDescriptor('nsu=http://test.org/UA/Data/ ;i=10845'), UAMonitoringParameters(1000)), EasyUAMonitoredItemArguments( None, endpointDescriptor, UANodeDescriptor('nsu=http://test.org/UA/Data/ ;i=10853'), UAMonitoringParameters(1000)), EasyUAMonitoredItemArguments( None, endpointDescriptor, UANodeDescriptor('nsu=http://test.org/UA/Data/ ;i=10855'), UAMonitoringParameters(1000)), ]) print('Processing data change events for 10 seconds...') time.sleep(10) print('Unsubscribing all monitored items...') client.UnsubscribeAllMonitoredItems() print('Waiting for 5 seconds...') time.sleep(5) print('Finished.')
' This example shows how to unsubscribe from changes of all items. ' ' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html . Imports OpcLabs.EasyOpc.UA Imports OpcLabs.EasyOpc.UA.OperationModel Namespace _EasyUAClient Friend Class UnsubscribeAllMonitoredItems Public Shared Sub Main1() ' Define which server we will work with. Dim endpointDescriptor As UAEndpointDescriptor = "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer" ' or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported) ' or "https://opcua.demo-this.com:51212/UA/SampleServer/" ' Instantiate the client object and hook events Dim client = New EasyUAClient() AddHandler client.DataChangeNotification, AddressOf client_DataChangeNotification Console.WriteLine("Subscribing...") client.SubscribeMultipleMonitoredItems(New EasyUAMonitoredItemArguments() _ { _ New EasyUAMonitoredItemArguments(Nothing, endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10845", 1000), _ New EasyUAMonitoredItemArguments(Nothing, endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10853", 1000), _ New EasyUAMonitoredItemArguments(Nothing, endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10855", 1000) _ } _ ) Console.WriteLine("Processing monitored item changed events for 10 seconds...") Threading.Thread.Sleep(10 * 1000) Console.WriteLine("Unsubscribing...") client.UnsubscribeAllMonitoredItems() Console.WriteLine("Waiting for 5 seconds...") Threading.Thread.Sleep(5 * 1000) End Sub Private Shared Sub client_DataChangeNotification(ByVal sender As Object, ByVal e As EasyUADataChangeNotificationEventArgs) ' Display value If e.Succeeded Then Console.WriteLine("{0}: {1}", e.Arguments.NodeDescriptor, e.AttributeData.Value) Else Console.WriteLine("{0} *** Failure: {1}", e.Arguments.NodeDescriptor, e.ErrorMessageBrief) End If End Sub End Class End Namespace
// This example shows how to unsubscribe from changes of all items. // // Find all latest examples here : https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html . type TClientEventHandlers126 = class procedure OnDataChangeNotification( ASender: TObject; sender: OleVariant; const eventArgs: _EasyUADataChangeNotificationEventArgs); end; procedure TClientEventHandlers126.OnDataChangeNotification( ASender: TObject; sender: OleVariant; const eventArgs: _EasyUADataChangeNotificationEventArgs); begin // Display the data if eventArgs.Succeeded then WriteLn(eventArgs.Arguments.NodeDescriptor.ToString, ': ', eventArgs.AttributeData.ToString) else WriteLn(eventArgs.Arguments.NodeDescriptor.ToString, ' *** Failure: ', eventArgs.ErrorMessageBrief); end; class procedure UnsubscribeAllMonitoredItems.Main; var Arguments: OleVariant; Client: TEasyUAClient; ClientEventHandlers: TClientEventHandlers126; EndpointDescriptor: string; MonitoredItemArguments1, MonitoredItemArguments2, MonitoredItemArguments3: _EasyUAMonitoredItemArguments; MonitoringParameters: _UAMonitoringParameters; begin EndpointDescriptor := //'http://opcua.demo-this.com:51211/UA/SampleServer'; //'https://opcua.demo-this.com:51212/UA/SampleServer/'; 'opc.tcp://opcua.demo-this.com:51210/UA/SampleServer'; // Instantiate the client object and hook events Client := TEasyUAClient.Create(nil); ClientEventHandlers := TClientEventHandlers126.Create; Client.OnDataChangeNotification := ClientEventHandlers.OnDataChangeNotification; WriteLn('Subscribing...'); MonitoringParameters := CoUAMonitoringParameters.Create; MonitoringParameters.SamplingInterval := 1000; MonitoredItemArguments1 := CoEasyUAMonitoredItemArguments.Create; MonitoredItemArguments1.EndpointDescriptor.UrlString := EndpointDescriptor; MonitoredItemArguments1.NodeDescriptor.NodeId.ExpandedText := 'nsu=http://test.org/UA/Data/ ;i=10845'; MonitoredItemArguments1.MonitoringParameters := MonitoringParameters; MonitoredItemArguments2 := CoEasyUAMonitoredItemArguments.Create; MonitoredItemArguments2.EndpointDescriptor.UrlString := EndpointDescriptor; MonitoredItemArguments2.NodeDescriptor.NodeId.ExpandedText := 'nsu=http://test.org/UA/Data/ ;i=10853'; MonitoredItemArguments2.MonitoringParameters := MonitoringParameters; MonitoredItemArguments3 := CoEasyUAMonitoredItemArguments.Create; MonitoredItemArguments3.EndpointDescriptor.UrlString := EndpointDescriptor; MonitoredItemArguments3.NodeDescriptor.NodeId.ExpandedText := 'nsu=http://test.org/UA/Data/ ;i=10855'; MonitoredItemArguments3.MonitoringParameters := MonitoringParameters; Arguments := VarArrayCreate([0, 2], varVariant); Arguments[0] := MonitoredItemArguments1; Arguments[1] := MonitoredItemArguments2; Arguments[2] := MonitoredItemArguments3; Client.SubscribeMultipleMonitoredItems(Arguments); WriteLn('Processing monitored item changed events for 10 seconds...'); PumpSleep(10*1000); WriteLn('Unsubscribing...'); Client.UnsubscribeAllMonitoredItems; WriteLn('Waiting for 5 seconds...'); Sleep(5*1000); WriteLn('Finished.'); VarClear(Arguments); FreeAndNil(Client); FreeAndNil(ClientEventHandlers); end;
// This example shows how to unsubscribe from changes of all items. // // Find all latest examples here : https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html . class ClientEvents { function DataChangeNotification($Sender, $E) { // Display the data if ($E->Succeeded) printf("s: s\n", $E->Arguments->NodeDescriptor, $E->AttributeData); else printf("s *** Failures\n", $E->Arguments->NodeDescriptor, $E->ErrorMessageBrief); } } $EndpointDescriptor = //"http://opcua.demo-this.com:51211/UA/SampleServer"; //"https://opcua.demo-this.com:51212/UA/SampleServer/"; "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"; // Instantiate the client object and hook events $Client = new COM("OpcLabs.EasyOpc.UA.EasyUAClient"); $ClientEvents = new ClientEvents(); com_event_sink($Client, $ClientEvents, "DEasyUAClientEvents"); printf("Subscribing...\n"); $MonitoringParameters = new COM("OpcLabs.EasyOpc.UA.UAMonitoringParameters"); $MonitoringParameters->SamplingInterval = 1000; $MonitoredItemArguments1 = new COM("OpcLabs.EasyOpc.UA.OperationModel.EasyUAMonitoredItemArguments"); $MonitoredItemArguments1->EndpointDescriptor->UrlString = $EndpointDescriptor; $MonitoredItemArguments1->NodeDescriptor->NodeId->ExpandedText = "nsu=http://test.org/UA/Data/ ;i=10845"; $MonitoredItemArguments1->MonitoringParameters = $MonitoringParameters; $MonitoredItemArguments2 = new COM("OpcLabs.EasyOpc.UA.OperationModel.EasyUAMonitoredItemArguments"); $MonitoredItemArguments2->EndpointDescriptor->UrlString = $EndpointDescriptor; $MonitoredItemArguments2->NodeDescriptor->NodeId->ExpandedText = "nsu=http://test.org/UA/Data/ ;i=10853"; $MonitoredItemArguments2->MonitoringParameters = $MonitoringParameters; $MonitoredItemArguments3 = new COM("OpcLabs.EasyOpc.UA.OperationModel.EasyUAMonitoredItemArguments"); $MonitoredItemArguments3->EndpointDescriptor->UrlString = $EndpointDescriptor; $MonitoredItemArguments3->NodeDescriptor->NodeId->ExpandedText = "nsu=http://test.org/UA/Data/ ;i=10855"; $MonitoredItemArguments3->MonitoringParameters = $MonitoringParameters; $arguments[0] = $MonitoredItemArguments1; $arguments[1] = $MonitoredItemArguments2; $arguments[2] = $MonitoredItemArguments3; $handleArray = $Client->SubscribeMultipleMonitoredItems($arguments); for ($i = 0; $i < count($handleArray); $i++) { printf("handleArray[d]d\n", $i, $handleArray[$i]); } printf("Processing monitored item changed events for 10 seconds...\n"); $startTime = time(); do { com_message_pump(1000); } while (time() < $startTime + 10); printf("Unsubscribing...\n"); $Client->UnsubscribeAllMonitoredItems; printf("Waiting for 5 seconds...\n"); $startTime = time(); do { com_message_pump(1000); } while (time() < $startTime + 5);
REM This example shows how to unsubscribe from changes of all items. REM REM Find all latest examples here : https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html . ' The client object, with events 'Public WithEvents Client7 As EasyUAClient Public Sub UnsubscribeAllMonitoredItems_Main_Command_Click() OutputText = "" Set Client7 = New EasyUAClient OutputText = OutputText & "Subscribing..." & vbCrLf Dim MonitoringParameters As New UAMonitoringParameters MonitoringParameters.SamplingInterval = 1000 Dim MonitoredItemArguments1 As New EasyUAMonitoredItemArguments MonitoredItemArguments1.endpointDescriptor.UrlString = "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer" MonitoredItemArguments1.nodeDescriptor.NodeId.expandedText = "nsu=http://test.org/UA/Data/ ;i=10845" Set MonitoredItemArguments1.MonitoringParameters = MonitoringParameters MonitoredItemArguments1.SetState ("Item1") Dim MonitoredItemArguments2 As New EasyUAMonitoredItemArguments MonitoredItemArguments2.endpointDescriptor.UrlString = "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer" MonitoredItemArguments2.nodeDescriptor.NodeId.expandedText = "nsu=http://test.org/UA/Data/ ;i=10853" Set MonitoredItemArguments2.MonitoringParameters = MonitoringParameters MonitoredItemArguments2.SetState ("Item2") Dim MonitoredItemArguments3 As New EasyUAMonitoredItemArguments MonitoredItemArguments3.endpointDescriptor.UrlString = "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer" MonitoredItemArguments3.nodeDescriptor.NodeId.expandedText = "nsu=http://test.org/UA/Data/ ;i=10855" Set MonitoredItemArguments3.MonitoringParameters = MonitoringParameters MonitoredItemArguments3.SetState ("Item3") Dim arguments(2) As Variant Set arguments(0) = MonitoredItemArguments1 Set arguments(1) = MonitoredItemArguments2 Set arguments(2) = MonitoredItemArguments3 Dim handleArray As Variant handleArray = Client7.SubscribeMultipleMonitoredItems(arguments) OutputText = OutputText & "Processing monitored item changed events for 10 seconds..." & vbCrLf Pause 10000 OutputText = OutputText & "Unsubscribing..." & vbCrLf Call Client7.UnsubscribeAllMonitoredItems OutputText = OutputText & "Waiting for 5 seconds..." & vbCrLf Pause 5000 Set Client7 = Nothing OutputText = OutputText & "Finished." & vbCrLf End Sub Public Sub Client7_DataChangeNotification(ByVal sender As Variant, ByVal eventArgs As EasyUADataChangeNotificationEventArgs) ' Display the data If eventArgs.Succeeded Then OutputText = OutputText & eventArgs.arguments.nodeDescriptor & ": " & eventArgs.AttributeData & vbCrLf Else OutputText = OutputText & eventArgs.arguments.nodeDescriptor & ": " & eventArgs.ErrorMessageBrief & vbCrLf End If End Sub
Rem This example shows how to unsubscribe from changes of all items. Rem Rem Find all latest examples here : https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html . Option Explicit ' Instantiate the client object and hook events Dim Client: Set Client = CreateObject("OpcLabs.EasyOpc.UA.EasyUAClient") WScript.ConnectObject Client, "Client_" WScript.Echo "Subscribing..." Dim MonitoringParameters: Set MonitoringParameters = CreateObject("OpcLabs.EasyOpc.UA.UAMonitoringParameters") MonitoringParameters.SamplingInterval = 1000 Dim MonitoredItemArguments1: Set MonitoredItemArguments1 = CreateObject("OpcLabs.EasyOpc.UA.OperationModel.EasyUAMonitoredItemArguments") MonitoredItemArguments1.EndpointDescriptor.UrlString = "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer" MonitoredItemArguments1.NodeDescriptor.NodeId.ExpandedText = "nsu=http://test.org/UA/Data/ ;i=10845" MonitoredItemArguments1.MonitoringParameters = MonitoringParameters Dim MonitoredItemArguments2: Set MonitoredItemArguments2 = CreateObject("OpcLabs.EasyOpc.UA.OperationModel.EasyUAMonitoredItemArguments") MonitoredItemArguments2.EndpointDescriptor.UrlString = "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer" MonitoredItemArguments2.NodeDescriptor.NodeId.ExpandedText = "nsu=http://test.org/UA/Data/ ;i=10853" MonitoredItemArguments2.MonitoringParameters = MonitoringParameters Dim MonitoredItemArguments3: Set MonitoredItemArguments3 = CreateObject("OpcLabs.EasyOpc.UA.OperationModel.EasyUAMonitoredItemArguments") MonitoredItemArguments3.EndpointDescriptor.UrlString = "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer" MonitoredItemArguments3.NodeDescriptor.NodeId.ExpandedText = "nsu=http://test.org/UA/Data/ ;i=10855" MonitoredItemArguments3.MonitoringParameters = MonitoringParameters Dim arguments(2) Set arguments(0) = MonitoredItemArguments1 Set arguments(1) = MonitoredItemArguments2 Set arguments(2) = MonitoredItemArguments3 Dim handleArray: handleArray = Client.SubscribeMultipleMonitoredItems(arguments) Dim i: For i = LBound(handleArray) To UBound(handleArray) WScript.Echo "handleArray(" & i & "): " & handleArray(i) Next WScript.Echo "Processing monitored item changed events for 10 seconds..." WScript.Sleep 10 * 1000 WScript.Echo "Unsubscribing..." Client.UnsubscribeAllMonitoredItems WScript.Echo "Waiting for 5 seconds..." WScript.Sleep 5 * 1000 Sub Client_DataChangeNotification(Sender, e) ' Display the data Dim display: If e.Exception Is Nothing Then display = e.AttributeData Else display = e.ErrorMessageBrief WScript.Echo e.Arguments.NodeDescriptor & ":" & display End Sub
Copyright © 2004-2024 CODE Consulting and Development, s.r.o., Plzen. All rights reserved. Web page: www.opclabs.com
Send Documentation Feedback. Resources: Knowledge Base, Product Downloads. Technical support: Online Forums, FAQ.Missing some example? Ask us for it on our Online Forums! You do not have to own a commercial license in order to use Online Forums, and we reply to every post.